package com.nfit.shopweb.web.api;

import com.github.pagehelper.PageInfo;
import com.nfit.shopmodel.entity.product.ProductSpec;
import com.nfit.shopmodel.vo.common.Result;
import com.nfit.shopmodel.vo.common.ResultCodeEnum;
import com.nfit.shopweb.service.ProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:ProductSpecController
 * Package:com.nfit.shopweb.web.api
 * Description
 *
 * @Author L
 * @Create 2024/12/16 15:00
 */
@RestController
@RequestMapping("/api/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecService productSpecService;

    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize){
       PageInfo pageInfo = productSpecService.page(pageNum,pageSize);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询所有商品规格
     */
    @GetMapping("/list")
    public Result list(){
       List<ProductSpec> list = productSpecService.list();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }


    @PostMapping("/save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/delete/{id}")
    private Result delete(@PathVariable("id") Long id){
        productSpecService.delete(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/update")
    private Result update(@RequestBody ProductSpec productSpec){
        productSpecService.update(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
